//导入自己的css
require('../css/course_introduction.css');

window.onload = function(){
    // 获取所需的dom
    let BASE_URL = 'http://139.9.177.51:8099';
    let videoDom = document.querySelector('.video')
    let nameDom = document.querySelector('.main-content .title h3')
    let calorieDom = document.querySelector('.main-content .title .calorie')
    let timeDom = document.querySelector('.main-content .title .time')
    let peopleDom = document.querySelector('.main-content .title .peoplenum')
    let nickNameDom = document.querySelector('.main-content .content .name h4')
    let desDom = document.querySelector('.main-content .content p')
    let frequencyDom = document.querySelector('.frequency')
    let instrumentDom = document.querySelector('.instrument')
    let btn = document.querySelector('button')

    // 获取课程id
    let courseId = localStorage.getItem('courseId')

    // 调用课程介绍的接口
    http.get('/sports/courseDetail',{'id':courseId},function(res){
        console.log(res);
        // 根据数据生成视频的图片展示
        let img = document.createElement('img')
        videoDom.appendChild(img)
        img.src = BASE_URL + res.data.imgurl;

        // 将对应的内容渲染到对应的标签文本中
        nameDom.textContent = res.data.name;
        calorieDom.textContent = res.data.calorie;
        timeDom.textContent = res.data.time;
        peopleDom.textContent = res.data.peoplenum;
        nickNameDom.textContent = localStorage.getItem('nickname')
        desDom.textContent = res.data.desc;
        frequencyDom.textContent = res.data.frequency;
        instrumentDom.textContent = res.data.instrument;

        // 将下个页面需要的数据存放在本地存储中
        localStorage.setItem('videos',JSON.stringify(res.data.fragments))
         
    })

    // 添加点击事件
    videoDom.addEventListener('click',function(){
        location.href = './course_video.html'
    })
    btn.addEventListener('click',function(){
        location.href = './course_video.html'
    })





}